<?php

/**
 * 首页
 * @copyright (c) 2013, Mr.Wang
 * @author Mr.Wang <281762391@qq.com>
 */
class ShopAction extends UserAction {

    public $dao;

    public function _initialize() {
        parent::_initialize();
        $this->model = D("Shop");
    }

    public function edit() {
        $shop = $this->model->where("shop_owner_id = " . session('uid'))->find();

        $area = array_filter(explode('_', $shop['shop_area']));

        $this->assign("area", $area);
        $this->assign("vo", $shop);
        if (IS_POST) {
            if (empty($_POST['country']) || empty($_POST['city'])) {
                $this->error("请选择所在地区");
            }
            if ($this->has_upload()) {
                $savePath            = "/Public/Uploads/" . date("Ymd") . "/";
                $file                = $this->upload($savePath);
                $_POST['shop_thumb'] = $savePath . $file[0]['savename'];
            }
            $_POST['shop_id']    = $shop['shop_id'];
            $_POST['shop_area']  = "_{$_POST['country']}_{$_POST['city']}_{$_POST['area']}_";
            if ($this->model->create()) {
                if ($this->model->save()) {
                    $this->success("修改成功！", __SELF__);
                } else {
                    $this->error("修改失败！");
                }
            } else {
                $this->error($this->model->getError());
            }
        } else {
            $this->assign("select_categorys", $select_categorys);
            $this->display();
        }
    }

    function _filter(&$map) {
        $map['uid'] = session('uid');
    }

    public function order() {
        //列表过滤器，生成查询Map对象
        $map = $this->_search();
        if (method_exists($this, '_filter')) {
            $this->_filter($map);
        }
        $model = D("Order");
        if (!empty($model)) {
            $this->_list($model, $map);
        }
        $this->display();
    }

}
